﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ewts.Project
{
    public partial class ProjectUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id = 0;
                if (Request["id"] != null && Request["id"].ToString().Trim() != "")
                {
                    id = int.Parse(Request["id"].ToString());
                }
                GetDropDown();
                GetDetile(id);
                
            }
        }

        private void GetDropDown()
        {
            int id = 0;
            if (Request["id"] != null && Request["id"].ToString().Trim() != "")
            {
                id = int.Parse(Request["id"].ToString());
            }
            //业务员
            string strWhere = " duty = '业务员'";
            DataTable dt = new DataLib.Accounts.Data.User().getUserList(strWhere);
            //数据源
            this.dropsalesman.DataSource = dt;
            //要绑定的字段
            this.dropsalesman.DataValueField = "UserID";
            // 显示的值
            this.dropsalesman.DataTextField = "TrueName";
            this.dropsalesman.DataBind();

            //地址
            string str = "";
            DataTable dt1 = new DataLib.BLL.CumtomerAddress().GetList(str).Tables[0];
            this.dropaddress.DataSource = dt1;
            this.dropaddress.DataValueField = "id";
            this.dropaddress.DataTextField = "address";
            this.dropaddress.DataBind();

        }

        private void GetDetile(int id)
        {
            DataLib.Model.ProjectsRelation pModel = new DataLib.Model.ProjectsRelation();
            DataLib.BLL.ProjectsRelation pBll = new DataLib.BLL.ProjectsRelation();
            pModel = pBll.GetModel(id);
            if (pModel != null)
            {
                this.txtProjectNum.Text = pModel.ProjectNum.ToString();
                //this.dropaddress.Text = pModel.Address.ToString();
                //this.dropsalesman.Text = pModel.AccountsUsersName.ToString();
            }
            

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = 0;
            if (Request["id"] != null && Request["id"].ToString().Trim() != "")
            {
                id = int.Parse(Request["id"].ToString());
            }
            DataLib.Model.ProjectsRelation pModel = new DataLib.Model.ProjectsRelation();
            DataLib.BLL.ProjectsRelation pBll = new DataLib.BLL.ProjectsRelation();
            //pModel.CumtomerAddressID = int.Parse(this.dropaddress.SelectedValue.ToString());
            //pModel.Address = this.dropaddress.SelectedItem.Text.ToString();
            //pModel.AccountsUsersID = int.Parse(this.dropsalesman.SelectedValue.ToString());
            //pModel.AccountsUsersName = this.dropsalesman.SelectedItem.Text.ToString();
            //pBll.Update(pModel);
            Response.Redirect("/Project/ProjectList.aspx?id=" + id + "");
        }

        protected void btnCancle_Click(object sender, EventArgs e)
        {
            int id = 0;
            if (Request["id"] != null && Request["id"].ToString().Trim() != "")
            {
                id = int.Parse(Request["id"].ToString());
            }
            Response.Redirect("/Project/ProjectList.aspx?id= " + id + "");
        }
    }
}